<?php
/**
 * User list administer
 *
 * @author Mario Schillermann <info@rockit-flash.com>
 * @encoding UTF-8 äöüßÖÄÜ
 * @copyright © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @package Page
 * @subpackage Index
 * @link $HeadURL$
 * @version SVN: $Id$
 * @phpVersion >=5
 * @todo
 */
class User_AppController extends Zend_Controller_Action
{
    /**
     * Initialisation
     *
     * @return void
     */
    public function init()
    {
    }
    /**
     * Show user list
     *
     * @return void
     */
    public function indexAction()
    {
        try {
            $this->setCss('window');
            $this->setCss('user');

            $layout = Zend_Layout::getMvcInstance();
            $layout->appTab = User_Model_Tab::render($this->view);

            if($this->_request->isPost()) {
                $this->_forward('delete');
            }

            if(($users = User_Model_Data::get()) === FALSE) {
                throw new Exception('Benutzer konnten nicht gelesen werden!');
            }
            $form = new User_Form_List;
            $this->view->form = $form->build($users);
        } catch (Exception $e) {

            $this->_forward('error', null, null, array('errorMessage' => $e->getMessage()));
        }
    }
    /**
     * User delete
     *
     * @throws Exception
     * @return void
     */
    public function deleteAction() {
        try {
            $value = $this->_request->getPost('userlist');

            if(empty($value)) {
                throw new Exception('Bitte einen Benutzer auswählt!');
            } else {
                if(User_Model_Data::delete($value) === FALSE) {
                    throw new Exception('Benutzer konnte nicht gelöscht werden!');
                }
                $this->view->user = $value;
            }
        } catch (Exception $e) {

            $this->_forward('error', null, null, array('errorMessage' => $e->getMessage()));
        }
    }
    /**
     * Error output
     *
     * @return void
     */
    public function errorAction() {

        $this->setCss('error');
        $this->view->errorMessage = $this->_request->errorMessage;
    }
    /**
     * Set css file
     *
     * @return void
     */
    protected function setCss($file) {

        $cssPath = $this->view->baseUrl('application/modules/user/public/css');
        $this->view
             ->headLink()
             ->appendStylesheet(
                 $cssPath . DIRECTORY_SEPARATOR .
                 $file . ".css"
               );
    }
}